﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using COM.OA.BLL;
using COM.OA.Entity;
using System.Collections.Generic;

public partial class linminchao_bbs_lt_lookOne : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        users loginuser = Session["loginuser"] as users;
        if (loginuser == null)
        {
            this.Response.Write(string.Format(GetRedirect.ALLREDIRECT, "../../login.aspx"));
        }
        else
        {
            IList<bbsrevert> brIlist;
            string page = this.Request["page"];
            int id = Int32.Parse(this.Request.QueryString["bbs_id"]);//帖子编号
            string where = "br_bbs_id='{0}'";
            where = string.Format(where, id);
            IList<bbsrevert> brIlists = bbsrevertBLL.Select(where);

            bbs bb = bbsBLL.Select(id);
            bb.bbs_id = id;
            bb.bbs_reads = bb.bbs_reads + 1;
            bb.bbs_reverts = brIlists.Count;
            bbsBLL.Update(bb);
            //总页数
            int count = brIlists.Count;
            float countd = count;
            double weiy = Math.Ceiling(countd / 2);
            int weiye = Int32.Parse(weiy.ToString());

            int pages = 1;
            int shangpage = 1;
            int xiapage = 1;
            if (page == null)
            {
                brIlist = bbsrevertBLL.Select(2, 1, where);//
                shangpage = pages;
                xiapage = 2;
            }
            else
            {
                pages = Int32.Parse(page);
                shangpage = pages - 1;
                xiapage = pages + 1;
                brIlist = bbsrevertBLL.Select(2, pages, where);
            }
            //作者查询
            users user = usersBLL.Select(Int32.Parse(bb.bbs_author));
            //部门查询
            department depm = departmentBLL.Select(user.u_dept_id);
            //档案查询
            employee em = employeeBLL.Select(user.u_em_id);
            this.Response.Write("<div align='center'><table width='100%' height='1' border='0'' cellpadding='0' cellspacing='0'><tr><td colspan='2'></td></tr><tr><td width='410' height='21' valign='baseline'><div align='right'><form action='' method='post' name='form11' id='form11' onsubmit='return dis1()'><input name='q' type='text' id='q' value=''><input name='submit' type=submit id='submit' style='FONT-SIZE: 12px; HEIGHT: 27px'  value= ' 查 询 ' ></form></div></td><td width='89' valign='baseline'><div align='center'><a href='lt_lookbbs.aspx'>论坛首页</a></div></td><td width='137' valign='top'><div align='center'><a href='lt_addlt.aspx'><img src='../img/new.gif' width='113' height='23' border='0'></a></div></td><td width='132' valign='top'><div align='center'><a href='lt_addHF.aspx?zhuti=" + bb.bbs_title + "&bbs_id=" + bb.bbs_id + "'><img src='../img/hui.gif' width='113' height='23' border='0'></a></div></td></tr><tr><td colspan='5'></td></tr></table></div>");
            this.Response.Write("<div align='center'><div align='center'><table width='760' border='0' cellpadding='0' cellspacing='0' background='../img/bw/line.gif'></table><div class='RoundedCorner'><b class='rtop'><b class='r1'></b><b class='r2'></b><b class='r3'></b><b class='r4'></b></b> <span class='style1'> 阅 读 帖 子</span></div><table width='100%' border='0' cellpadding='5' cellspacing='1' bgcolor='#5AAE18'><tr bgcolor='#FFFFFF'><td height='21' align='center' valign='top' bgcolor='#FFFFFF'>&nbsp;</td><td width='834' valign='top' bgcolor='#FFFFFF'><table width='99%' border='0' cellspacing='0' cellpadding='0'><tr><td width='528'><span class='style4'>主题:<span style='font-weight: bold'>" + bb.bbs_title + "</span></span></td><td width='277'><a href='#' title='IP:192.168.1.106'><img src='../img/bbs_ip.gif' width='13' height='15' border='0'></a> 更新:<font color='#FF0000'>2008-7-6 11:11:37</font></td></tr></table></td></tr>");
            this.Response.Write("<tr bgcolor='#FFFFFF' style='word-break:break-all;Width:fixed'><td width='116' height='160' align='center' valign='top'><br><img src='../" + em.em_photo + " ' width='100' height='120' border='0'></a><br><a href='#' title='" + depm .dept_department+ "'>"+user.u_username+"<br><p></p></td><td valign='top'><p>" + bb.bbs_content + "</p><p align='right'><br><br><br><br></p> <table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'><tr><td><img src='../img/sigline.gif' width='406' height='16'></td></tr></table><p align='right'> <span class='style9'>2008-7-6 11:10:39</span>  <br><br>");
            //管理员权限
            string wheres = "op_u_id='{0}'";
            wheres = string.Format(wheres, loginuser.u_id);
            //帖子回复查询
            IList<operate> oplist = operateBLL.Select(wheres);
            foreach(operate o in oplist){
                if (o.op_pop_id > 2)
                {
                    this.Response.Write("<img src='../img/update.gif' width='12' height='13'/><A HREF='lt_update.aspx?id=" + bb.bbs_id + "')'>修改本帖</A>");
                    this.Response.Write("<img src='../img/del.gif' width='12' height='13'/><A HREF='lt_delelt.aspx?id=" + bb.bbs_id + "')'>删除本帖</A>");
                }
            }
            this.Response.Write("</td></tr>");
            int lll = pages * 2 - 1;
            foreach (bbsrevert br in brIlist)
            {
                users u = usersBLL.Select(br.br_u_id);
                this.Response.Write("<tr bgcolor='#FFFFFF' style='word-break:break-all;Width:fixed'><td width='116' height='160' align='center' valign='top'><br><img src='../"+em.em_photo+"' width='100' height='120' border='0'><br><a href='#' title='"+depm.dept_department+"'>"+u.u_username+"</a><br>第<font color='red'><strong>" + lll + "</strong></font>楼<br> <p></p></td>");
                this.Response.Write("</td><td valign='top'><p>" + br.br_revertcontent + "</p><p align='right'><br><br><br><br></p> <table width='100%' border='0' cellpadding='0' cellspacing='0' bgcolor='#FFFFFF'><tr><td><img src='../img/sigline.gif' width='406' height='16'></td></tr></table><p align='right'> <span class='style9'>" + br.br_reverttime + "</span>");
                //权限 管理员 本人
                foreach (operate o in oplist)
                {
                    if (o.op_pop_id > 2 )
                    {
                        this.Response.Write("<p align='right'> <br><br><img src='../img/update.gif' width='16' height='16'>　<a href='lt_updateHF.aspx?id=" + br.br_id + "&bbs_id=" + id + "&bt=" + bb.bbs_title + "' title='更新本帖..'>修改</a>");
                    }
                }
                //权限 管理员
                foreach (operate o in oplist)
                {
                    if (o.op_pop_id > 2)
                    {
                        this.Response.Write("　<img src='../img/del.gif' width='12' height='13'><a href='lt_delmyhuifu.aspx?id=" + br.br_id + "&bbs_id=" + id + "' onClick='return confirm('您确定要删除帖子吗？')' title='删除本帖..'>删除</a></p> </td></tr>");
                    }
                }
                lll = lll + 1;

            }
            this.Response.Write("<tr bgcolor='#FFFFFF' ><td></td><td colspan='1' style='width: 175px; height: 21px; text-align: left;' colspan='2'><div  align='center'>");
            //分页
            if (shangpage == pages || shangpage == 0)
            {
                this.Response.Write("首页");

            }
            else
            {
                this.Response.Write("<a href='lt_lookOne.aspx?bbs_id=" + id + "&page=" + shangpage + "'>上一页</a>");
            }
            if (pages == weiye || weiye == 0 || weiye == 1)
            {

                this.Response.Write("&nbsp; &nbsp; &nbsp; 尾页");
            }
            else
            {

                this.Response.Write("&nbsp; &nbsp; &nbsp; <a href='lt_lookOne.aspx?bbs_id=" + id + "&page=" + xiapage + "'>下一页</a>");
            }
            this.Response.Write("<p>&nbsp; (总共" + count + "条帖子)</p></div></td></tr>");
            //作者是当前登陆拥护u_id
            this.Response.Write("</table><table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td><form name='form1 runat='server' method='post' action='lt_kuaisu.aspx?bbs_id=" + bb.bbs_id + "' onSubmit='return dis()'><table width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#5AAE18'><tr bgcolor='#FFFFFF'><td width='165' valign='top'><div align='right'><br><span class='style9'>快速回复:</span></div></td><td width='804'><table width='100' border='0' cellpadding='0' cellspacing='0'><tr><td>&nbsp;</td><td>&nbsp;</td><td><textarea name='content' cols='70' rows='8' id='content'></textarea></td></tr></table><br><input  runat='server' name='submit' type='submit' id='submit' name='submita' style='FONT-SIZE: 12px; HEIGHT: 27px' onclick='return check()'  value= ' 回 帖 '/><br><br></td></tr></table></form></td></tr></table>");
            this.Response.Write("<span class='style8'><img src='../img/up.gif' width='17' height='12'><a href='javascript:history.go(-1)'>返 回</a></span></div>");


        }
    }
}
